<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>大嘿嘿后台管理</title>
		<link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
		<script src="js/jquery-1.12.4.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
		
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/antd.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/axios-0.18.0.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/interfaceuRL.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="app">
		  <form class="form-horizontal">
		    <div class="form-group">
		      <label for="inputPassword3" class="col-sm-2 control-label">文章标题</label>
		      <div class="col-sm-10">
		        <input type="text" class="form-control" id="title" placeholder="" :value="title">
		      </div>
		    </div>
		    <div class="form-group">
		      <label for="inputPassword3" class="col-sm-2 control-label">分类栏目</label>
		      <div class="col-sm-10">
				  <select name="type" id="type" class="form-control">
				  	<option value="type2" v-for="item in type2" :value="item.gid">{{item.gname}}</option>
				  </select>
		      </div>
		    </div>
			<div class="form-group">
			  <label for="inputPassword3" class="col-sm-2 control-label">文章内容</label>
			  <div class="col-sm-10">
				<textarea name="textarea" class="form-control" id="content" placeholder="说点什么.....最少输入10个字符"  :value="content"></textarea>
			  </div>
			</div>
			<div class="form-group">
			  <label for="inputPassword3" class="col-sm-2 control-label">发布日期</label>
			  <div class="col-sm-10">
				<span style="width: 100%;display: inline-block;background: #BCBCBC;height: 30px;line-height: 30px;" >{{time | timeFormat}}</span> 
			  </div>
			</div>
			<div class="form-group">
					      <label for="inputEmail3" class="col-sm-2 control-label">文章作者</label>
					      <div class="col-sm-10">
					        <input type="text" class="form-control" id="author"  :value="author">
					      </div>
					    </div>
		    <div class="form-group">
		      <div class="col-sm-offset-2 col-sm-10">
		       <button type="button" @click="update()" class="btn btn-primary " >保存</button>
		      <a href="wenzgl.html"><button type="submit" class="btn btn-default">取消</button></a>
		      </div>
		    </div>
		  </form>
		
			
		 </div>
		 
	</body>
</html>
<script type="text/javascript">
	var vm = new Vue({
		el: "#app",
		data: {
			title:"",
			author:"",
			content:"",
			time:"",
			type:"",
			superid:0,
			supername:0,
			aid:"",
			type2:"",
		},
		beforeMount:function(){
			var _this=this;
			_this.aid=window.location.href.split("?")[1].split("=")[1];
			axios({
			   //请求方式，'GET'或者'POST'
			    method: 'POST',
			    //请求地址
			    url: findItemById()+_this.aid,
			}).then(res => {
			     	console.log(res.data);
					_this.title=res.data[0].title;
					_this.author=res.data[0].author;
					_this.content=res.data[0].content;
					_this.time=res.data[0].time;
					_this.type=res.data[0].type;
					_this.superid=res.data[0].superid;
					_this.type2=res.data[1];
					
			}).catch(err => {
				alert("服务出错了!")
				
			  });
		},
		methods: {
			update: function() {
				if($("#title").val()==""){
					alert("文章主题不能为空！！！")
				}else{
				axios({
					method:"POST",
					url:articeUpdate(),
					data:{
						"title":$("#title").val(),
						"author":$("#author").val(),
						"content":$("#content").val(),
						"time":this.time,
						"type":$("#type").val(),
						"superid":this.superid,
						"supername":this.supername,
						"aid":this.aid
						
					},

				}).then(res => {
					console.log(res.data);
					
					window.location.href="wenzgl.html"
				}).catch(err => {
					alert("服务出错了！")
				})
				
				}			
			}
			
		},
		filters: {
				timeFormat: function(time) {
					var date = new Date(time);
					var strDate = date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() + "   " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() ;
					return strDate;
				}
		},
	})
</script>
